home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_400
/
420_01
/
defs.h
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-21
|
4KB
|
144 lines
/*
// defs.h -- $@4pK\E*$JDj5A$HA4%U%!%$%k6&DL$JItJ,(J
//
// created in 2/11/1994
*/
#ifndef _DEFS_H_
#define _DEFS_H_
#include <stdio.h>
#include <setjmp.h>
/* 1. Define a bitwidth of each integer correctly according to your system. */
typedef short int int16;
typedef long int int32;
typedef unsigned int uint32;
/* 2. Choose a correct byte-order. */
#define LITTLEENDIAN
/*#define BIGENDIAN*/
/* 3. What character is used as a directory separator in your OS? Choose the correct one. */
#define DSEPARATOR '/'
/*#define DSEPARATOR '\\' */
/* Ok. That's all. (maybe) */
#define error(Message) {\
fprintf( stderr, "%s: " Message "\n", Program, File );\
longjmp( ErrorEntry, 1 ); }
#define AllocateScreen() {\
if ( Screen != NULL ) free (Screen);\
if ( (Screen = (int16*)malloc ((Size = Width * Height * 2) + 256)) == NULL )\
error ("%s: Insufficient memory"); }
#define AllocateBuffer() {\
if ( (BitBuffer = (unsigned char*)malloc (BitBufferSize)) == NULL )\
error ("%s: Insufficient memory");\
BitLength = 0;\
BitCache = 0;\
BitBufferLength = BitBufferSize; }
#define AllocateBufferForWriting() {\
if ( (BitBuffer = (unsigned char*)malloc (BitBufferSize)) == NULL )\
error ("%s: Insufficient memory");\
BitLength = 0;\
BitCache = 0;\
BitBufferLength = 0; }
#define ReverseByteOrder() {\
char *p = (char*)Screen, c;\
int i;\
for ( i = 0; i < Size; i += 2 ) {\
c = p[i]; p[i] = p[i + 1]; p[i + 1] = c; } }
#define BitBufferSize 32768
#define BitLoad(Length,Result) {\
register uint32 Code;\
register int TakenCount;\
int ShiftCount, DemandLength;\
DemandLength = Length;\
Code = BitCache;\
ShiftCount = (DemandLength <= BitLength) ? 32 - DemandLength : 32 - BitLength;\
TakenCount = 32 - ShiftCount;\
Code >>= ShiftCount;\
BitCache <<= TakenCount;\
DemandLength -= TakenCount;\
BitLength -= TakenCount;\
if ( DemandLength > 0 ) {\
if ( BitBufferLength == BitBufferSize )\
BitBufferLoad();\
BitCache = (unsigned int)BitBuffer[BitBufferLength]\
| ((unsigned int)BitBuffer[BitBufferLength + 1] << 8)\
| ((unsigned int)BitBuffer[BitBufferLength + 2] << 16)\
| ((unsigned int)BitBuffer[BitBufferLength + 3] << 24);\
BitBufferLength += 4;\
Code <<= DemandLength;\
BitLength = 32 - DemandLength;\
Code |= BitCache >> BitLength;\
BitCache <<= DemandLength;\
}\
Result = Code; }
#define BitWrite(Length,BitPattern) {\
register int ShiftCount;\
int BitShift, RestCount, DemandLength;\
DemandLength = Length;\
RestCount = 32 - BitLength;\
ShiftCount = (DemandLength <= RestCount) ? DemandLength : RestCount;\
BitShift = (DemandLength > ShiftCount) ? DemandLength - ShiftCount : 0;\
BitCache <<= ShiftCount;\
BitCache |= (BitPattern) >> BitShift;\
DemandLength -= ShiftCount;\
BitLength += ShiftCount;\
if ( DemandLength > 0 ) {\
if ( BitBufferLength == BitBufferSize )\
BitBufferFlush();\
BitBuffer[BitBufferLength++] = BitCache & 0xff;\
BitBuffer[BitBufferLength++] = (BitCache >> 8) & 0xff;\
BitBuffer[BitBufferLength++] = (BitCache >> 16) & 0xff;\
BitBuffer[BitBufferLength++] = (BitCache >> 24) & 0xff;\
BitCache = (BitPattern);\
BitLength = DemandLength; } }
#define UNKNOWN 0
#define ALPHA 1
#define BETA 2
#define GAMMA 3
#define DELTA 4
#define PIC 5
#define MAG 6
#define MAKI 7
#define PI 8
#define ML1 9
#define PPM 10
#define PBM 11
#define NumberofFormats 12
extern int16 *Screen;
extern int32 Width, Height, Size;
extern FILE *fp;
extern jmp_buf ErrorEntry;
extern char *Program, *File;
extern unsigned char *BitBuffer;
extern uint32 BitCache;
extern int BitLength;
extern int BitBufferLength;
extern unsigned char BitField[];
extern int MaxColorGuaranteed;
extern int16 Red[], Green[], Blue[], Palette[];
extern char *Extension[];
extern char *Format[];
extern void BitBufferLoad();
extern void BitBufferFlush();
extern void BitBufferLastFlush();
extern int istrcmp( char *s1, char *s2 );
extern int InferFormat( char *File );
extern void Initialize();
#endif /* _DEFS_H_ */